<?php

//当前时间戳
if(!function_exists('now')){
  function now(){
    return time();
  }
}

//当前页面url
if(!function_exists('current_url')){
  function current_url(){
    $current_url = strtolower(str_replace('.','/',request()->controller().'.'.request()->action()));
    return $current_url;
  }
}

//base加密
if(!function_exists('base_encode')){
  function base_encode($source,$salt = PN){
    $salt = 'Dink';
    $result = base64_encode($salt.base64_encode($salt.$source));
    return $result;
  }
}

//base解密
if(!function_exists('base_decode')){
  function base_decode($source,$salt = PN){
    $salt = 'Dink';
    $result = substr(base64_decode(substr(base64_decode($source),strlen($salt))),strlen($salt));
    return $result;
  }
}

//curl_get
if(!function_exists('curl_get')){
  function curl_get($url){
    $curl = curl_init();
    curl_setopt($curl,CURLOPT_URL,$url);
    curl_setopt($curl,CURLOPT_HEADER,false);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
    $result = json_decode(curl_exec($curl),true);
    curl_close($curl);
    return $result;
  }
}

//curl_post
if(!function_exists('curl_post')){
  function curl_post($url,$data){
    $curl = curl_init();
    curl_setopt($curl,CURLOPT_URL,$url);
    curl_setopt($curl,CURLOPT_HEADER,false);
    curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
    curl_setopt($curl,CURLOPT_POST,true);
    curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($data,JSON_UNESCAPED_UNICODE));
    $result = json_decode(curl_exec($curl),true);
    curl_close($curl);
    return $result;
  }
}
